package org.example.listener;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.util.Map;

/**
 * 验证多个监听器是否是使用的是同一个channel？
 */
@Slf4j
@Component
public class MultiQueueListener {

    @RabbitListener(queues = {"order"}, concurrency = "4")
    public void process1(Map<String, String> message, Channel channel, Message message111) throws IOException, InterruptedException {
        Connection connection = channel.getConnection();
        log.info("111current channel number is : {}", channel.getChannelNumber());
        log.info("Receiver message info: {}", message);
        Thread.sleep(3000);
    }

    @RabbitListener(queues = {"test"}, concurrency = "1")
    public void process2(String message, Channel channel, Message message111) throws IOException, InterruptedException {
        Connection connection = channel.getConnection();
        log.info("222current channel number is : {}", channel.getChannelNumber());
        log.warn("delivery Tag is : {}", message111.getMessageProperties().getDeliveryTag());
        log.info("Receiver message info: {}", message);
        System.out.println("消息消费完成！");
    }

}
